package com.xhh.learning.record.jvm;

/**
 * @author: Administrator
 * @date: 2018/7/26 10:39
 * 逃逸分析
 */
public class EscapeAnalysis {

    /**
     * 1. -server -verbose:gc
     * 2. -server -verbose:gc -XX:+DoEscapeAnalysis
     *
     */
    public static void main(String[] args) {

        long start = System.nanoTime();
        for (int i = 0; i < 100000000; i++) {
            A a = new A(i);
            alloc();
        }
        long end = System.nanoTime();
        System.out.println(end-start);
    }

    public static void alloc(){
        byte[] b=new byte[2];
        b[0]=1;
    }
}

class A{
    int a;

    public A(int a){
        this.a = a;
    }
}
